﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Linq.Expressions;
using Newtonsoft.Json.Linq;

using CanDoo;
using CanDoo.Core;
using CanDoo.Data;
using CanDoo.Web;
using CanDoo.Secutiry;
using CanDoo.FineUI;
using CanDoo.Extensions;
using CanDoo.Core.Context;
using CanDoo.Oil.Core.Models;
using CanDoo.Oil.Core.Contracts;
using CanDoo.Admin.Core.Models;
using CanDoo.Admin.Core.Contracts;
using FineUIPro;

namespace CanDoo.Oil.WebApp.cusCustomer
{
    public partial class View : PageBase
    {
        public ICustomerContract CustomerContract { get; set; }
        public IOilSalesSerialNumContract OilSalesSerialNumContract { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var id = Request.QueryString["id"].ToLong();
                var Entity = CustomerContract.GetById(id);
                if (Entity != null)
                {
                    if (Entity.CardType == 1 || Entity.CardType == 2 || Entity.CardType == 4)
                    {
                        this.TabStrip1.Tabs[4].Hidden = true;
                        this.TabStrip1.Tabs[5].Hidden = true;
                        this.TabStrip1.Tabs[6].Hidden = true;

                        this.TabStrip1.Tabs[0].Title = "客户信息";
                        this.TabStrip1.Tabs[1].Title = "充值记录";
                        this.TabStrip1.Tabs[2].Title = "资金流水";
                        this.TabStrip1.Tabs[3].Title = "取油日志";

                        this.TabStrip1.Tabs[0].IFrameUrl = "/oil/cusCustomer/edit.aspx?act=view&id=" + id;//客户信息
                        this.TabStrip1.Tabs[1].IFrameUrl = "/oil/logMoneyChange/Default.aspx?customerId=" + id;//充值记录
                        this.TabStrip1.Tabs[2].IFrameUrl = "/oil/logMoneyChange/Default.aspx?customerId=" + id;//资金流水
                        this.TabStrip1.Tabs[3].IFrameUrl = "/oil/logGetOil/Default.aspx?customerId=" + id;//取油日志
                    }
                    else
                    {
                        var mEntity = OilSalesSerialNumContract.FirstOrDefault(p => p.CustomerId == Entity.Id);
                        if (mEntity != null)
                        {
                            this.TabStrip1.Tabs[0].Title = "客户信息";
                            this.TabStrip1.Tabs[1].Title = "油桶状态";
                            this.TabStrip1.Tabs[2].Title = "售油日志";
                            this.TabStrip1.Tabs[3].Title = "油桶更换日志";
                            this.TabStrip1.Tabs[4].Title = "绑定状态";
                            this.TabStrip1.Tabs[5].Title = "绑定日志";
                            this.TabStrip1.Tabs[6].Title = "清洗日志";

                            this.TabStrip1.Tabs[0].IFrameUrl = "/oil/cusCustomer/edit.aspx?act=view&id=" + id;//客户信息
                            this.TabStrip1.Tabs[1].IFrameUrl = "/oil/storeOilSerialNum/OnSale.aspx?oilsalesserialnumId=" + mEntity.Id;//销售状态
                            this.TabStrip1.Tabs[2].IFrameUrl = "/oil/logGetOil/Default.aspx?oilsalesserialnumId=" + mEntity.Id;//取油日志
                            this.TabStrip1.Tabs[3].IFrameUrl = "/oil/logChangeOilDrum/Default.aspx?oilsalesserialnumId=" + mEntity.Id;//油桶更换日志
                            this.TabStrip1.Tabs[4].IFrameUrl = "/oil/storeOilSalesSerialNum/Default.aspx?customerId=" + id;//绑定状态
                            this.TabStrip1.Tabs[5].IFrameUrl = "/oil/logBindDevice/Default.aspx?customerId=" + id;//绑定日志
                            this.TabStrip1.Tabs[6].IFrameUrl = "/oil/logCleanRecord/Default.aspx?oilsalesserialnumId=" + mEntity.Id;//清洗日志
                        }
                        else
                        {
                            this.TabStrip1.Tabs[0].Title = "客户信息";
                            this.TabStrip1.Tabs[1].Title = "未绑定售油机";
                            this.TabStrip1.Tabs[1].Enabled = false;

                            this.TabStrip1.Tabs[0].IFrameUrl = "/oil/cusCustomer/edit.aspx?act=view&id=" + id;//客户信息
                            //this.TabStrip1.Tabs[1].IFrameUrl = "/oil/logCleanRecord/Default.aspx?oilsalesserialnumId=" + mEntity.Id;//销售状态

                            this.TabStrip1.Tabs[2].Hidden = true;
                            this.TabStrip1.Tabs[3].Hidden = true;
                            this.TabStrip1.Tabs[4].Hidden = true;
                            this.TabStrip1.Tabs[5].Hidden = true;
                            this.TabStrip1.Tabs[6].Hidden = true;
                        }

                        
                    }
                }

                
            }
        }
    }
}